<div class="container">
    <h2>Select Username</h2>
    Username <select name="forma" ONCHANGE="location = this.options[this.selectedIndex].value;">
        <?php
        $sth = $this->model->GetUsernames();
        while ($data = $sth->fetch()) {
            $Username = $data['username'];
            $MemberId = $data['memberId'];
            if($MemberId == $_SESSION['memberIdViewer']) {
            ?>      
            <option value="<?php echo URL;?>viewer/getmemberview/<?php echo $MemberId; ?>" selected="selected" ><?php echo $Username ?></option>
            
            <?php
            } else { ?>
            <option value="<?php echo URL;?>viewer/getmemberview/<?php echo $MemberId; ?>"><?php echo $Username ?></option>    
            <?php
            }
        }
        ?>
    </select>
</div>


    <div id="tabs">
        <ul class="sortable">

            <?php
            $sth = $this->model->GetRounds();
            $TabIndex = 0;
            while ($data = $sth->fetchColumn()) {
                $RoundNr = $data['nr'];
                $TabIndex++;
                ?>      
                <li><a href="#fragment-<?php echo $TabIndex ?>"><span>Round <?php echo $RoundNr ?></span></a></li>
                <?php
            }
            ?>    
        </ul>

        <?php
        //Print Data in each tab
        $sthTab = $this->model->GetRounds();
        $TabIndex = 0;
        while ($data = $sthTab->fetch()) {
            $RoundNr = $data['nr'];
            $RoundStatus = $data['roundStatus'];
            if (strcmp($RoundStatus, 'SetPicks') == 0) {
                $SetPicksEnabled = true;
            } else {
                $SetPicksEnabled = false;
            }



            $TabIndex++;
            ?>
            <div id="fragment-<?php echo $RoundNr ?>">
                <h3>Status: <?php echo $RoundStatus; ?> </h3>
                <?php if ($RoundStatus == 'SetPicks') {
                    ?>
                    <h3>Cannot see Picks for this round</h3>
                    <?php
                } else {
                    ?>
                    <table>
                        <tr>
                            <td>
                                <div class="divPointsHeader">
                                    <h3>Points</h3>
                                </div>
                            </td>
                            <td>
                                <div class="divMatchGroupHeader">
                                    <h3>Match</h3>
                                </div>
                            </td>
                        </tr>
                        <tr>
                            <td>

                                <script type="text/javascript">
                                    $(document).ready(function() {
                                        $( "#sortable_<?php echo $TabIndex ?>" ).disableSelection();
                                    });
                                </script>

                                <ul class ="sortable" id="sortable_<?php echo $TabIndex; ?>">
                                    <?php
                                    //Get Priority for Points with extreme SQL statement
                                    $sthPriority = $this->model->GetPriorityPoints($RoundNr, $_SESSION['memberIdViewer']);
                                    while ($data = $sthPriority->fetch()) {
                                        $points = $data['points'];
                                        $priority = $data['priority'];
                                        $color_index = $this->model->GetPicksStatus($data['picksResult'], $data['matchResult']);
                                        if ($color_index == -1)
                                            $color = "#DF0101";
                                        if ($color_index == 0)
                                            $color = "#FFFFFF";
                                        if ($color_index == 1)
                                            $color = "#3ADF00";
                                        ?>
                                        <li id="Round_<?php echo $RoundNr; ?>_Priority_<?php echo $priority; ?>">
                                            <div class="divPoints" style="background-color:<?php echo $color; ?>">
                                        <?php echo $points . PHP_EOL; ?>
                                            </div>
                                        </li>
                                                <?php
                                            }
                                            ?>    
                                </ul>
                            </td>

                            <td>
                                <ul class="unsortable" >
        <?php
        //Get Matchs in default priority            
        $sthMatchs = $this->model->GetPicksInfo($RoundNr, $_SESSION['memberIdViewer']);
        while ($data = $sthMatchs->fetch()) {
            $PicksResult = $data['picksResult'];
            $NameTeamA = $data['nameTeamA'];
            $DisplayNameTeamA = $data['displayNameTeamA'];
            $ImageTeamA = $data['imageNameTeamA'];
            $NameTeamB = $data['nameTeamB'];
            $DisplayNameTeamB = $data['displayNameTeamB'];
            $ImageTeamB = $data['imageNameTeamB'];
            $pickId = $data['pickId'];


            $MedalA = 'nomedal';
            $MedalB = 'nomedal';
            if (strcmp($PicksResult, 'Team A wins') == 0) {
                $MedalA = 'goldmedal';
            } else if (strcmp($PicksResult, 'Team B wins') == 0) {
                $MedalB = 'goldmedal';
            }
            ?> 
                                        <li>
                                            <div class="divMatchGroup">
                                                <table>
                                                    <tr>
                                                        <td>
                                                            <div class="divTeam" id="Round_<?php echo $RoundNr; ?>_Team_A_pickId_<?php echo $pickId; ?>">
                                                                <img src="<?php echo URL ?>public/image/flags/<?php echo $ImageTeamA ?>" alt=""/>
                                                                <img 
            <?php if ($SetPicksEnabled) { ?>
                                                                        id="idPickSymbol_A_<?php echo $pickId; ?>"
                                                                <?php } ?> src="<?php echo URL ?>public/image/<?php echo $MedalA ?>.png" alt=""/>                                                            <?php echo $DisplayNameTeamA; ?>
                                                            </div>
                                                        </td>
                                                        <td>VS</td>
                                                        <td style="text-align: right;">
                                                            <div class="divTeam" id="Round_<?php echo $RoundNr; ?>_Team_B_pickId_<?php echo $pickId; ?>">
            <?php echo $DisplayNameTeamB ?> 
                                                                <img 
                                                                <?php if ($SetPicksEnabled) { ?>
                                                                        id="idPickSymbol_B_<?php echo $pickId; ?>" 
                                                                <?php } ?> src="<?php echo URL ?>public/image/<?php echo $MedalB ?>.png" alt=""/>
                                                                <img src="<?php echo URL ?>public/image/flags/<?php echo $ImageTeamB ?>" alt=""/>

                                                            </div>
                                                        </td>
                                                    </tr>
                                                </table>
                                            </div>
                                        </li>
            <?php
        }
        ?>
                                </ul>
                            </td>
                    </table>
    <?php } ?>
            </div> 
                <?php
            }
            ?>

</div> 
</div> 
